<!--
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-10-19 16:56:42
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-10-19 21:52:36
 * @FilePath: \作业\public\index.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./static/css/bootstrap.min.css">
</head>


<body>
    <!-- 给一个容器 -->
    <div class="container">
        <div class="row text-center">
            <h1>学生信息管理系统</h1>
            <hr>

            <a href="http://127.0.0.1:3000/index.html" class="btn btn-success" id="shou">首页</a>
            <a href="http://127.0.0.1:3000/add.html" class="btn btn-warning" id="tian">添加</a>

            <br>
            <br>
        </div>
        <div class="row">

            <table id="tb" class="table table-bordered table-condensed table-hover table-responsive text-center">
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>操作</th>
                </tr>
            </table>

        </div>
    </div>

</body>
<script>
    let table = document.querySelector('#tb')
    console.log(table)
    function fun() {
        let xhr = new XMLHttpRequest()
        console.log(xhr.readyState)
        xhr.open("get", "/sign", true)
        console.log(xhr.readyState)
        xhr.send()
        console.log(xhr.readyState)
        xhr.onreadystatechange = function () {
            console.log(xhr.readyState);
            if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    // console.log(xhr.response)
                    let data = JSON.parse(xhr.response)
                    console.log(data)
                    // var aaa = [1, 2, 3]
                    // console.log(aaa)
                    let Tag = ''
                    for (var i = 0; i < data[0].length; i++) {
                        console.log(data[0][i].name) //打印每一个数组元素
                        Tag += `<tr>
                        <td>${data[0][i].id}</td>
                        <td>${data[0][i].name}</td>
                        <td>${data[0][i].sex}</td>
                        <td>${data[0][i].age}</td>
                        <td>
                            <a href="" class="btn btn-danger">删除</a>
                            <a href="" class="btn btn-warning">修改</a>
                        </td>
                            </tr>`
                    }
                    table.innerHTML = Tag
                }
            }
        }
    }
    fun()
</script>
<script src="./static/js/jquery.min.js"></script>

</html>